package longrise.phone.com.bjjt_henan.Utils;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.longrise.android.util.Util;
import com.longrise.android.widget.LLinearLayoutView;

import longrise.phone.com.bjjt_henan.widget.HeNanDialog;

/**
 * Created by Administrator on 2016/5/12.
 */
public class UiUtils {

    private static HeNanDialog dialog1;

    /**
     * 双选对话框
     *
     * @param context    上下文
     * @param ResourceId 显示在dialog上的图片的资源文件id
     * @param title      标题
     * @param content    内容
     * @param leftStr    左边btn内容
     * @param rightStr   右边btn内容
     * @param leftClick
     * @param rightClick
     */
    public static HeNanDialog showDialog(Context context, Integer ResourceId, String title, String content, String leftStr, String rightStr,
                                         View.OnClickListener leftClick, View.OnClickListener rightClick) {
        HeNanDialog dialog = null;
        if (null != ResourceId) {
            dialog = new HeNanDialog(context, ResourceId).builder();
        } else {
            dialog = new HeNanDialog(context).builder();
        }
        dialog.setTitle(title);
        dialog.setShowTitle(false);
        dialog.setShowEditText(false);
        dialog.setMsg(content);
        dialog.setNegativeButton(leftStr, leftClick);
        dialog.setPositiveButton(rightStr, rightClick);
        dialog.setCancelable(false);
        dialog.show();
        return dialog;
    }
    /**
     * 单按钮强制跳转的对话框
     *
     * @param context
     * @param content
     * @param login
     * @param rightClick
     * @return
     */
    public static HeNanDialog showSingleDialog(Context context, Integer ResourceId, String content, String login,
                                               View.OnClickListener rightClick) {
        dialog1 = null;
        if (null != ResourceId) {
            dialog1 = new HeNanDialog(context, ResourceId).builder();
        } else {
            dialog1 = new HeNanDialog(context).builder();
        }
        dialog1.setTitle("提示");
        dialog1.setShowTitle(false);
        dialog1.setShowEditText(false);
        dialog1.setMsg(content);
        dialog1.setPositiveButton(login, rightClick);
        dialog1.setCancelable(false);
        dialog1.show();
        return dialog1;
    }

    public static void missDialog() {
        dialog1.dismiss();
    }

    /**
     * 确定取消提示对话框
     *
     * @param context
     * @param content
     * @param leftClick
     * @param rightClick
     */
    public static HeNanDialog showDialog(Context context, String content, View.OnClickListener leftClick,
                                         View.OnClickListener rightClick) {
        return showDialog(context, null, "提示", content, "取消", "确定", leftClick, rightClick);
    }

    private static TextView textView;

    /**
     * 显示waiting对话框
     *
     * @param text
     */
    public static Dialog showProcessDialogPro(Context context, String text) {

        Dialog processDialog = new Dialog(context, com.longrise.bjjt_lib.R.style.dialog_style);
        processDialog.setCanceledOnTouchOutside(false);

        LLinearLayoutView dialogView = new LLinearLayoutView(context);
        dialogView.setBackgroundColor(Color.parseColor("#55000000"), -10, -10, -10, -10, Util.dip2px(context, 5), 0,
                Color.parseColor("#55000000"));
        dialogView.setGravity(Gravity.CENTER);
        dialogView.setOrientation(LinearLayout.VERTICAL);

        // 进度条
        ProgressBar bar = new ProgressBar(context);
        bar.setIndeterminate(true);
        bar.setIndeterminateDrawable(context.getResources().getDrawable(com.longrise.bjjt_lib.R.drawable.lcontainerview_anim_loading));
        int w = Util.dip2px(context, 30);
        dialogView.addView(bar, w, w);

        textView = new TextView(context);
        textView.setText(text);
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(14);
        textView.setTextColor(Color.parseColor("#FFFFFF"));
        textView.setPadding(0, Util.dip2px(context, 10), 0, 0);
        dialogView.addView(textView);

        int widthDialog = Util.dip2px(context, 100);
        LinearLayout.LayoutParams dialogLP = new LinearLayout.LayoutParams(widthDialog, widthDialog);
        processDialog.setContentView(dialogView, dialogLP);
        // add by huxin
        processDialog.show();
        //
        dialogLP = null;
        return processDialog;
    }

    public static void changeText(String text) {
        textView.setText(text);
    }
}
